/*
 * FileBrowser.java
 *
 * Created on __DATE__, __TIME__
 */

package forms;

import java.io.File;

import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.filechooser.FileFilter;

/**
 *
 * @author  __USER__
 */
public class FileBrowser extends javax.swing.JFrame {

	private static JLabel pathLabel;

	/** Creates new form FileBrowser 
	 * @param jLabel1 */
	public FileBrowser(JLabel jLabel1) {
		initComponents();
		this.pathLabel = jLabel1;
	}

	//GEN-BEGIN:initComponents
	// <editor-fold defaultstate="collapsed" desc="Generated Code">
	private void initComponents() {

jFileChooser1 = new javax.swing.JFileChooser();

setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

jFileChooser1.setAcceptAllFileFilterUsed(false);
jFileChooser1.setFileFilter(new FileFilter() {
	
	@Override
	public String getDescription() {
		return "Image-Files (*.bmp, *.jpg, *.jpeg, *.png, *.gif)";
	}
	
	@Override
	public boolean accept(File f) {
        String fName = f.getName().toUpperCase();
        if (fName.endsWith(".BMP") || fName.endsWith(".JPG") || fName.endsWith(".JPEG") || fName.endsWith(".PNG") || fName.endsWith(".GIF") || f.isDirectory()) {
            return true;
        } else {
            return false;   
        }
	}
});
jFileChooser1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jFileChooser1ActionPerformed(evt);
}
});

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jFileChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jFileChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
);

pack();
}// </editor-fold>

	//GEN-END:initComponents

	private void jFileChooser1ActionPerformed(java.awt.event.ActionEvent evt) {
		JFileChooser chooser = (JFileChooser) evt.getSource();
		if (JFileChooser.APPROVE_SELECTION.equals(evt.getActionCommand())) {
			//			jFileChooser1.setVisible(false);
			pathLabel
					.setText(jFileChooser1.getSelectedFile().getAbsolutePath());
			dispose();
		} else if (JFileChooser.CANCEL_SELECTION.equals(evt.getActionCommand())) {
			//			jFileChooser1.setVisible(false);
			dispose();
		}
	}

	/**
	 * @param args the command line arguments
	 */
	public static void main(String args[]) {
		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				new FileBrowser(pathLabel).setVisible(true);
			}
		});
	}

	//GEN-BEGIN:variables
	// Variables declaration - do not modify
	private javax.swing.JFileChooser jFileChooser1;
	// End of variables declaration//GEN-END:variables

}